//
//  ViewController.m
//  tom
//
//  Created by 楼楚 on 15/10/13.
//  Copyright © 2015年 Chu Lou. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tom;

@end

@implementation ViewController
/*
 1.将重复代码复制到新的方法中
 2.根据需要调整参数
 */
- (void) tomAnimationWithName:(NSString *)name count:(NSInteger)count
{
//    如果正在动画 直接退出
    if ([self.tom isAnimating]) return;
    NSMutableArray *arrayM = [NSMutableArray array];
    
    //    add pics
    for (int i=0; i < count; i++) {
        //        pic name
        NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg",name,i];
        UIImage *image = [UIImage imageNamed:imageName];
        [arrayM addObject:image];
    }
    //     设置动画数组
    self.tom.animationImages = arrayM;
    //    重复一次
    self.tom.animationRepeatCount = 1;
    //    动画时长
    self.tom.animationDuration = self.tom.animationImages.count * 0.07;
    
    //    开始动画
    [self.tom startAnimating];
}
- (IBAction)knockout
{
    [self tomAnimationWithName:@"knockout" count:81];
}

- (IBAction)eatbird
{
    [self tomAnimationWithName:@"eat" count:40];
////    序列帧动画 顺序播放一组图片
//    
////    动画图片的数组
//    NSMutableArray *arrayM = [NSMutableArray array];
//    
////    add pics
//    for (int i=0; i < 40; i++) {
////        pic name
//        NSString *imageName = [NSString stringWithFormat:@"eat_%02d.jpg",i];
//        UIImage *image = [UIImage imageNamed:imageName];
//        [arrayM addObject:image];
//            }
////     设置动画数组
//    self.tom.animationImages = arrayM;
////    重复一次
//    self.tom.animationRepeatCount = 1;
////    动画时长
//    self.tom.animationDuration = self.tom.animationImages.count * 0.07;
//    
////    开始动画
//    [self.tom startAnimating];
    
}
- (IBAction)drink
{
    [self tomAnimationWithName:@"drink" count:81];
}
- (IBAction)cymbal {
    [self tomAnimationWithName:@"cymbal" count:13];
}
- (IBAction)fart {
    [self tomAnimationWithName:@"fart" count:28];
}
- (IBAction)pie {
    [self tomAnimationWithName:@"pie" count:24];
}
- (IBAction)scratch {
    [self tomAnimationWithName:@"scratch" count:56];
}
- (IBAction)stomach {
    [self tomAnimationWithName:@"stomach" count:34];
}
- (IBAction)angry {
    
    [self tomAnimationWithName:@"angry" count:26];
}
- (IBAction)footright {
    
    [self tomAnimationWithName:@"footRight" count:30];
}
- (IBAction)footleft {
    
    [self tomAnimationWithName:@"footLeft" count:30];
}



@end
